//
//  YiZhiFuViewController.m
//  GuoBang
//
//  Created by fengshuai on 16/4/29.
//  Copyright © 2016年 梧桐树. All rights reserved.
//

#import "YiZhiFuViewController.h"
#import "DaiJinTableViewCell.h"
#import "MyBookIngTableViewCell.h"

@interface YiZhiFuViewController ()<UITableViewDelegate, UITableViewDataSource>
{
    DaiJinTableViewCell *daijinCell;
    MyBookIngTableViewCell *myBookCell;
    NSMutableArray *statusArr;
}

@property (nonatomic, strong) UITableView *setTableView;
@property (nonatomic, strong) NSArray *titleArr;


@end

@implementation YiZhiFuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setupNVA];
    [self setupUI];
    [self setupData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setupNVA
{
    self.title=@"已支付";
    //设置返回按键
    //返回按键颜色
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    //返回按键图标
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                         forBarMetrics:UIBarMetricsDefault];
}

- (void)leftAction:(UIBarButtonItem *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setupData
{
    
    
}

- (void)setupUI
{
    statusArr = [NSMutableArray arrayWithObjects:@"0",@"0",@"0", nil];
    self.setTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 120) style:UITableViewStyleGrouped];
    self.setTableView.delegate = self;
    self.setTableView.dataSource = self;
    self.setTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.setTableView];
    
    
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    
    return 1;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"customcell"];
    
    
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyBookIngTableViewCell" owner:self options:nil];
    if (nib.count > 0) {
        myBookCell = [nib objectAtIndex:0];
        
        
        if ([statusArr[indexPath.section] isEqualToString:@"0"]) {
            myBookCell.zhifushijianLabel.hidden = YES;
            myBookCell.zhifuDate.hidden = YES;
            myBookCell.shangpingLabel.hidden = YES;
            myBookCell.shangpinMoney.hidden = YES;
            myBookCell.shengchengDate.hidden = YES;
            myBookCell.shengchengLabel.hidden = YES;
            myBookCell.xiangqinBtn.tag = indexPath.section;
            [myBookCell.xiangqinBtn addTarget:self action:@selector(xiangqingOpenAction:) forControlEvents:UIControlEventTouchUpInside];
            
        }else if ([statusArr[indexPath.section] isEqualToString:@"1"]){
            myBookCell.xiangqinBtn.tag = indexPath.section;
            [myBookCell.xiangqinBtn addTarget:self action:@selector(xiangqingCloseAction:) forControlEvents:UIControlEventTouchUpInside];
            
            
        }
        
        myBookCell.dingdanzhuangtai.text = @"已支付";
        
        myBookCell.topLine.image = [UIImage imageNamed:@"order_ico_line.png"];
        
        myBookCell.leftBtn.tag = 1000 + indexPath.section;
        myBookCell.rightBtn.tag = 2000 + indexPath.section;
        
        [myBookCell.leftBtn setTitle:@"订单评价" forState:UIControlStateNormal];
        [myBookCell.rightBtn setTitle:@"分享订单" forState:UIControlStateNormal];
        [myBookCell.leftBtn setImage:[UIImage imageNamed:@"order_ico_appraise.png"] forState:UIControlStateNormal];
         [myBookCell.rightBtn setImage:[UIImage imageNamed:@"order_ico_share.png"] forState:UIControlStateNormal];
        
        
        [myBookCell.leftBtn addTarget:self action:@selector(weixinAction:) forControlEvents:UIControlEventTouchUpInside];
        [myBookCell.rightBtn addTarget:self action:@selector(zhifubaoAction:) forControlEvents:UIControlEventTouchUpInside];
        
        
        cell = myBookCell;
    }
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}





-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([statusArr[indexPath.section] isEqualToString:@"1"]) {
        return 190;
    }
    return 140;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    
    
    return 15;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1;
}


// 详情打开
- (void)xiangqingOpenAction:(UIButton *)sender
{
    
    [statusArr replaceObjectAtIndex:sender.tag withObject:@"1"];
    [self.setTableView reloadData];
    
}

// 详情关闭
- (void)xiangqingCloseAction:(UIButton *)sender
{
    [statusArr replaceObjectAtIndex:sender.tag withObject:@"0"];
    [self.setTableView reloadData];
}


- (void)weixinAction:(UIButton *)sender
{
    
    NSLog(@"我是左边的%ld",sender.tag);
    [self.delegate helpPush];
}

- (void)zhifubaoAction:(UIButton *)sender
{
    
    NSLog(@"我是右边的%ld",sender.tag);
    
    
}


- (void)rightAction
{
    
}
- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}

@end
